// pages/find/index1.js
var t = getApp(),
  a = t.requirejs("core");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loaded: false,
    list: [],
    page: 1,
    show: false,
    delBtnWidth: 88,//删除按钮宽度单位（rpx）
  },
  calling: function (t) {
    a.phone(t)
  },
  onLoad: function (e) {
    this.setData(e)
    var that=this;
    that.getlist();
  },
  onShow: function () {
   
  },
  /**
     * 获取员工列表信息
     */
  getlist: function () {
    var t = this;
    a.get("shop/user_list", {
      page: t.data.page,
      shop_id: t.data.shop_id
    }, function (i) {
      if (i.code == 0) {
        var e = { show: true };
        i.info.length > 0 && (e.page = t.data.page + 1, e.list = t.data.list.concat(i.info), i.info.length < 10 && (e.loaded = true));
        i.info.length == 0 && (e.loaded = true);
        e.list = i.info;
        e.count = i.info.length;
        t.setData(e)
      } else {
        a.alert(i.msg)
      }
    }, true)
  },
  
  consume: function (e) {
    var data = a.pdata(e);
    wx.navigateTo({
      url: '/pages/vip_man/consume?id=' + data.id + '&nm_type=' + data['nm_type']
    })
  },
 
  /**
    * 下拉刷新
    */
  onPullDownRefresh: function () {
    this.setData({
      list: [],
      page: 1,
      loaded: false
    })
    this.getlist()
    wx.stopPullDownRefresh();
  },

  /**
   *上拉加载
   */
  onReachBottom: function () {
    console.log('加载更多')
    this.data.loaded || this.getlist()
  },

  /**
    * 滑动删除页面效果
 */
  touchS: function (e) {
    return;
    if (e.touches.length == 1) {
      this.setData({
        //设置触摸起始点水平方向位置
        startX: e.touches[0].clientX
      });
    }
  },
  touchM: function (e) {
    return;
    if (e.touches.length == 1) {
      //手指移动时水平方向位置
      var moveX = e.touches[0].clientX;
      //手指起始点位置与移动期间的差值
      var disX = this.data.startX - moveX;
      var delBtnWidth = this.data.delBtnWidth;
      var txtStyle = "";
      if (disX == 0 || disX < 0) {//如果移动距离小于等于0，文本层位置不变
        txtStyle = "left:0px";
      } else if (disX > 0) {//移动距离大于0，文本层left值等于手指移动距离
        txtStyle = "left:-" + disX + "px";
        if (disX >= delBtnWidth) {
          //控制手指移动距离最大值为删除按钮的宽度
          txtStyle = "left:-" + delBtnWidth + "px";
        }
      }
      //获取手指触摸的是哪一项
      var index = e.currentTarget.dataset.index;
      var list = this.data.list;
      list[index].txtStyle = txtStyle;
      //更新列表的状态
      this.setData({
        list: list
      });
    }
  },
  touchE: function (e) {
    return;
    console.log(e)
    if (e.changedTouches.length == 1) {
      //手指移动结束后水平位置
      var endX = e.changedTouches[0].clientX;
      //触摸开始与结束，手指移动的距离
      var disX = this.data.startX - endX;
      var delBtnWidth = this.data.delBtnWidth;
      //如果距离小于删除按钮的1/2，不显示删除按钮
      var txtStyle = disX > delBtnWidth / 2 ? "left:-" + delBtnWidth + "px" : "left:0px";
      //获取手指触摸的是哪一项
      var index = e.currentTarget.dataset.index;
      var list = this.data.list;
      list[index].txtStyle = txtStyle;
      //更新列表的状态
      this.setData({
        list: list
      });
    }
  },
  //获取元素自适应后的实际宽度
  getEleWidth: function (w) {
    var real = 0;
    try {
      var res = wx.getSystemInfoSync().windowWidth;
      var scale = (750 / 2) / (w / 2);//以宽度750px设计稿做宽度的自适应
      // console.log(scale);
      real = Math.floor(res / scale);
      return real;
    } catch (e) {
      return false;
      // Do something when catch error
    }
  },
  initEleWidth: function () {
    var delBtnWidth = this.getEleWidth(this.data.delBtnWidth);
    this.setData({
      delBtnWidth: delBtnWidth
    });
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})